package com.cnap.multiclouldmgmt.model.scale;

import cn.hutool.core.util.IdUtil;
import com.cnap.multiclouldmgmt.model.scale.db.ScalingConfigPO;
import com.cnap.multiclouldmgmt.util.JsonUtil;
import com.cnap.multiclouldmgmt.util.TokenUtils;
import io.swagger.annotations.ApiModelProperty;

import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * <类文件描述>
 *
 * @author xc
 **/
public class ScalingConfigDTO {
    @ApiModelProperty(value = "配置名称")
    private String configName;
    @ApiModelProperty(value = "云资源管理处配置模板的id")
    private String cloudResourceIds;
    @ApiModelProperty(value = "云商信息")
    private String provider;

    private String accountName;

    /**
     * get
     *
     * @return AccountName
     */
    public String getAccountName() {
        return accountName;
    }

    /**
     * set
     *
     * @param accountName accountName
     */
    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    /**
     * get
     *
     * @return ConfigName
     */
    public String getConfigName() {
        return configName;
    }

    /**
     * set
     *
     * @param configName configName
     */
    public void setConfigName(String configName) {
        this.configName = configName;
    }

    /**
     * get
     *
     * @return CloudResourceIds
     */
    public String getCloudResourceIds() {
        return cloudResourceIds;
    }

    /**
     * set
     *
     * @param cloudResourceIds cloudResourceIds
     */
    public void setCloudResourceIds(String cloudResourceIds) {
        this.cloudResourceIds = cloudResourceIds;
    }

    /**
     * get
     *
     * @return Provider
     */
    public String getProvider() {
        return provider;
    }

    /**
     * set
     *
     * @param provider provider
     */
    public void setProvider(String provider) {
        this.provider = provider;
    }

    @Override
    public String toString() {
        return JsonUtil.objectToJsonStr(this);
    }

    /**
     * 转换成po
     *
     * @return po
     */
    public ScalingConfigPO toPO() {
        ScalingConfigPO configPO = new ScalingConfigPO();
        // 暂时使用userName代替userId
        configPO.setUserId(TokenUtils.getUserName());
        configPO.setUserName(TokenUtils.getUserName());
        configPO.setConfigName(configName);
        configPO.setCloudResourceIds(Arrays.asList(cloudResourceIds.split(",")));
        configPO.setCreateTime(LocalDateTime.now());
        configPO.setId(IdUtil.simpleUUID());
        configPO.setProvider(this.provider);
        configPO.setAccountName(this.accountName);
        return configPO;
    }
}
